import {Mesh} from '../model/Mesh.ts'
export const d3_cylinder = (r=1, n=20) =>{

  const vertexes = []
  const indices = []
  const texCoord = []
  const colors = []

  for (let i=0;i<n;i++){
    const u=i/n;
    const theta = Math.PI*2*u;
    const x = r*Math.cos(theta);
    const z = r*Math.sin(theta);
    vertexes.push(x, -1/2, z)
    texCoord.push(u,0)
    vertexes.push(x, 1/2, z)
    texCoord.push(u,1)

    colors.push(Math.random(), Math.random(), Math.random(), 1)
    colors.push(Math.random(), Math.random(), Math.random(), 1)

  }

  for(let i=0;i<n;i++){
    indices.push(i*2, i*2+i, (i+1)*2)
    indices.push(i*2+1, (i+1)*2, (i+1)*2+1)
  }
  return new Mesh({vertexes, indices, colors})
}
